import 'package:hive/hive.dart';

part 'collection_model.g.dart';

@HiveType(typeId: 12)
class CollectionModel extends HiveObject {
  @HiveField(0)
  String userId;

  @HiveField(1)
  List<String> collectedTeamIds;

  @HiveField(2)
  List<String> collectedShareIds;

  @HiveField(3)
  List<String> collectedVideoIds;

  @HiveField(4)
  List<String> collectedScanResultIds;

  CollectionModel({
    required this.userId,
    List<String>? collectedTeamIds,
    List<String>? collectedShareIds,
    List<String>? collectedVideoIds,
    List<String>? collectedScanResultIds,
  }) : this.collectedTeamIds = collectedTeamIds ?? [],
       this.collectedShareIds = collectedShareIds ?? [],
       this.collectedVideoIds = collectedVideoIds ?? [],
       this.collectedScanResultIds = collectedScanResultIds ?? [];

  // 添加收藏项
  void addTeam(String teamId) {
    if (!collectedTeamIds.contains(teamId)) {
      collectedTeamIds.add(teamId);
    }
  }

  void addShare(String shareId) {
    if (!collectedShareIds.contains(shareId)) {
      collectedShareIds.add(shareId);
    }
  }

  void addVideo(String videoId) {
    if (!collectedVideoIds.contains(videoId)) {
      collectedVideoIds.add(videoId);
    }
  }

  void addScanResult(String scanResultId) {
    if (!collectedScanResultIds.contains(scanResultId)) {
      collectedScanResultIds.add(scanResultId);
    }
  }

  // 移除收藏项
  void removeTeam(String teamId) {
    collectedTeamIds.remove(teamId);
  }

  void removeShare(String shareId) {
    collectedShareIds.remove(shareId);
  }

  void removeVideo(String videoId) {
    collectedVideoIds.remove(videoId);
  }

  void removeScanResult(String scanResultId) {
    collectedScanResultIds.remove(scanResultId);
  }
}
